<style>
    @media screen and (max-width: 500px) {

        .layui-table-view {
            width: 100% !important;
            overflow-x: scroll !important;
            left: 0 !important;
        }

        .layui-table-box {
            width: 1200px !important;
            box-sizing: border-box;
        }

    }
</style>
<form class="layui-form seller-form">
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">提货单号：</label>
            <div class="layui-input-inline seller-inline-3">
                <input type="text" name="id" id="id" placeholder="提货单号" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">订单号：</label>
            <div class="layui-input-inline seller-inline-3">
                <input type="text" name="order_id" id="order_id" placeholder="订单号" autocomplete="off"
                    class="layui-input">
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">下单时间：</label>
            <div class="layui-input-inline seller-inline-4">
                <input type="text" name="date" id="date" placeholder="开始时间 到 结束时间" autocomplete="off"
                    class="layui-input">
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">提货状态：</label>
            <div class="layui-input-inline seller-inline-3">
                <select name="status" id="status" autocomplete="off">
                    <option value="">-- 全部 --</option>
                    <option value="1">未提货</option>
                    <option value="2">已提货</option>
                </select>
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">提货门店：</label>
            <div class="layui-input-inline seller-inline-3">
                <select name="store_id" id="store_id" autocomplete="off">
                    <option value="">-- 全部 --</option>
                    {foreach $store as $v}
                    <option value="{$v.id}">{$v.store_name}</option>
                    {/foreach}
                </select>
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">提货人名：</label>
            <div class="layui-input-inline seller-inline-3">
                <input type="text" name="name" id="name" placeholder="提货人姓名" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">提货电话：</label>
            <div class="layui-input-inline seller-inline-3">
                <input type="tel" name="mobile" id="mobile" placeholder="提货人电话" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-inline">
            <div class="layui-input-inline">
                <button class="layui-btn layui-btn-sm" lay-submit lay-filter="*"><i
                        class="iconfont icon-chaxun"></i>筛选</button>
                <button class="layui-btn layui-btn-sm" lay-submit lay-filter="export-lading"><i
                        class="iconfont icon-msnui-cloud-download" style="font-size: 20px !important;"></i>导出</button>
            </div>
        </div>
    </div>
</form>

<div class="table-body">
    <table class="" id="ladingTable" lay-filter="ladingTable"></table>
</div>
<div id="exportLading" style="display: none;">
    <form class="layui-form export-form" action="">
        <div class="layui-form-item">
            <div class="layui-margin-10">
                <blockquote class="layui-elem-quote layui-text">
                    请先选中或筛选要导出的订单
                </blockquote>
            </div>

            <div class="layui-inline">
                <label class="layui-form-label">任务名称：</label>
                <input type="text" name="taskname" lay-verify="title" style="width:200px;" placeholder="请输入任务名称"
                    autocomplete="off" class="layui-input">
            </div>
        </div>
    </form>
</div>
<script>
    var table;
    layui.use(['table', 'form', 'layer', 'laydate'], function () {
        var form = layui.form, layer = layui.layer;
        table = layui.table;
        //时间插件
        layui.laydate.render({
            elem: '#date',
            range: '到',
            format: 'yyyy-MM-dd'
        });
        table.render({
            elem: '#ladingTable',
            height: 'full-139',
            cellMinWidth: '80',
            page: 'true',
            limit: '20',
            id: 'ladingTable',
            url: "{:url('manage/BillLading/index')}",
            response: {
                statusName: 'status',
                statusCode: 1
            },
            cols: [[ //标题栏
                { type: 'checkbox' },
                { type: 'numbers' },
                { field: 'id', title: '提货单号', align: 'center', width: 150 },
                { field: 'order_id', title: '订单号', align: 'center', width: 150 },
                { field: 'store_name', title: '提货门店', align: 'center', width: 150, sort: true },
                { field: 'name', title: '提货人名', align: 'center' },
                { field: 'mobile', title: '提货电话', align: 'center' },
                { field: 'status_name', title: '提货状态', align: 'center', sort: true },
                { field: 'ctime', title: '下单时间', align: 'center', sort: true },
                { field: 'option', title: '操作', align: 'center', toolbar: '#ladingBar' }
            ]]
        });

        //筛选条件
        form.on('submit(*)', function (data) {
            table.reload('ladingTable', {
                where: data.field,
                page: { curr: 1 }
            });
            return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
        });

        //监听工具条
        table.on('tool(ladingTable)', function (obj) {
            var data = obj.data;
            var layEvent = obj.event;

            if (layEvent === 'info') {
                //获取详情
                JsGet("{:url('manage/billLading/info')}?id="+data.id, function(e){
                    layer.open({
                        type: 1,
                        title: '详情',
                        area: ['650px', '310px'], //宽高
                        content: e
                    });
                });
            } else if (layEvent === 'write') {
                //核销提货单
                if (data.status === 2) {
                    layer.msg('该提货单已经核销，无需重复核销');
                } else {
                    layer.confirm('确认核销该提货单吗？', {
                        btn: ['确认', '取消'] //按钮
                    }, function () {
                        JsPost("{:url('manage/BillLading/write')}", {'id': data.id}, function(e){
                            layer.msg(e.msg, { time: 1500 }, function () {
                                table.reload('ladingTable');
                            });
                        });
                    }, function () {

                    });
                }
            } else if (layEvent === 'del') {
                //删除
                layer.confirm('真的删除么', { icon: 3 }, function (index) {
                    JsGet("{:url('manage/billLading/delLading')}?id=" + data.id, function (res) {
                        if (res.status) {
                            obj.del();
                            layer.close(index);
                        }
                        layer.msg(res.msg);
                    });
                });
            }
        });

        //修改保存
        $(document).on('click', '.editBtn', function () {
            var data = $('#edit-form').serialize();
            JsPost('{:url("manage/BillLading/info")}', data, function(e){
                if (e.status) {
                    layer.msg(e.msg, { time: 1500 }, function () {
                        layer.closeAll();
                        table.reload('ladingTable');
                    });
                } else {
                    layer.msg(e.msg);
                }
            });
            return false;
        });
        //提货单导出
        layui.form.on('submit(export-lading)', function (data) {

            layer.open({
                type: 1,
                title: '提货单导出',
                area: ['400px', '290px'], //宽高
                btn: ['确定', '取消'],
                content: $("#exportLading").html(),
                yes: function () {
                    //判断是否有选中
                    var checkStatus = layui.table.checkStatus('ladingTable');
                    var checkData = checkStatus.data;
                    var length = checkStatus.data.length;
                    var ids = [];
                    if (length) {
                        $.each(checkData, function (i, obj) {
                            ids.push(obj.id);
                        });
                    }

                    //判断是否有选中
                    var filter = $(".seller-form").serialize();
                    filter += '&ids=' + ids;
                    $(".export-form:last").append("<input type='hidden' name='filter' value='" + filter + "'>");
                    var data = $(".export-form:last").serializeArray();

                    data.push({ 'name': 'model', 'value': 'BillLading' });

                    JsPost("{:url('Ietask/export')}", data, function (res) {
                        layer.msg(res.msg, { time: 1500 }, function () {
                            if (res.status) {
                                table.reload('ladingTable');
                                layer.closeAll();
                            }
                        });
                    }
                    );
                }, btn2: function () {
                    layer.closeAll();
                }
            });
            return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
        });
    });
</script>

<script type="text/html" id="ladingBar">
    <a class="layui-btn layui-btn-xs" lay-event="info">详情</a>
    <a class="layui-btn layui-btn-xs" lay-event="write">核销</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>